home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / mdxdos23 / client.c < prev    next >
C/C++ Source or Header  |  1996-07-10  |  5KB  |  250 lines

  1. #include    "multix.h"
  2.  
  3. #include    <stdio.h>
  4. #include    <stdlib.h>
  5.  
  6. #include    <string.h>
  7. #include    <time.h>
  8.  
  9. #include    "appl.h"
  10. TMdxProcId    MyId;
  11.  
  12. void    ApplDataReplyReceived(
  13. TMdxEvent    *Event
  14. )
  15. {
  16.     TMdxSRMsgInfo    *MsgInfo;
  17.  
  18.     /*
  19.     "Event->Data"    holds the information abount the new message.
  20.     */
  21.  
  22.     MsgInfo =    (TMdxSRMsgInfo    *)Event->Data;
  23.  
  24.     /*    First    thing is to check MsgCode of the new message    */
  25.  
  26.     switch(MsgInfo->Received.MsgCode)
  27.     {
  28.         case    ApplGetTimeReplyCode    :
  29.         {
  30.             TMdxTime    MdxTime    =    0;
  31.             MdxMsgRead(MsgInfo->Received.Msg,(UInt8Ptr)&MdxTime,sizeof(MdxTime));
  32.             MdxTime =    MdxTimeTo_time_t(MdxTime);
  33.             printf("(%ld) Time Received From %ld - %s",MdxGetCurrTimerValue(),Event->ProcId,ctime((time_t *)&MdxTime));
  34.             MdxReply(MsgInfo,MdErrNoError);
  35.         }
  36.         break;
  37.         default                     :    break;
  38.     }
  39. }
  40.  
  41.  
  42. void    ApplCallCompleted(
  43. TMdxEvent    *Event
  44. )
  45. {
  46.     printf("(%ld) Call Completed to Process (%ld)\n",MdxGetCurrTimerValue(),Event->ProcId);
  47. }
  48.  
  49.  
  50. void    ApplInitReceived(void)
  51. {
  52.  
  53.     TMdxProcessParams    ProcessParams;
  54.     TMdxLinkParams    LinkParams;
  55.  
  56.     /*
  57.     You may choose to use onw or more links of the types specified.
  58.     Un comment the relevent "MdxOpenLink()".
  59.  
  60.     You may change the parameters for the links.
  61.     */
  62.  
  63.  
  64.     memset(&LinkParams,0,sizeof(LinkParams));
  65.     strcpy(LinkParams.LinkName.Byte,"com2");
  66.     LinkParams.LinkType                =    MdxLinkTypeAsyncLocal;
  67.     LinkParams.ConnectMode            =    MdxConnectModeCall;
  68.     LinkParams.ConnectTimeout        =    0x7fffffff;
  69.     LinkParams.MaxConnectRetries    =    -1;
  70.     LinkParams.ConnectRetriesDelay    =    200;
  71.     LinkParams.LinkBaud             =    19200;
  72.     LinkParams.UseDlcFraming        =    True;
  73.     LinkParams.ImAliveInterval        =    400l;
  74.     LinkParams.MaxPollRetries        =    2;
  75.     LinkParams.L1MaxSendSize        =    256;
  76.     /*
  77.     MdxOpenLink(&LinkParams);
  78.     */
  79.     memset(&LinkParams,0,sizeof(LinkParams));
  80.     strcpy(LinkParams.LinkName.Byte,"MdxFs");
  81.     LinkParams.LinkType                =    MdxLinkTypeSpxIpx;
  82.     LinkParams.ConnectMode            =    MdxConnectModeCall;
  83.     LinkParams.ConnectTimeout        =    1000;
  84.     LinkParams.MaxConnectRetries    =    -1;
  85.     LinkParams.ConnectRetriesDelay    =    200;
  86.     LinkParams.UseDlcFraming        =    True;
  87.     LinkParams.MaxPollRetries        =    10;
  88.     LinkParams.L1MaxSendSize        =    500;
  89.     /*
  90.     MdxOpenLink(&LinkParams);
  91.     */
  92.  
  93.     memset(&LinkParams,0,sizeof(LinkParams));
  94.     strcpy(LinkParams.LinkName.Byte,"MdxFs");
  95.     LinkParams.LinkType                =    MdxLinkTypeNetBios;
  96.     LinkParams.ConnectMode            =    MdxConnectModeCall;
  97.     LinkParams.ConnectTimeout        =    0x7fffffffl;
  98.     LinkParams.ConnectRetriesDelay    =    300l;
  99.     LinkParams.L1MaxSendSize        =    1024;
  100.     LinkParams.MaxConnectRetries    =    -1l;
  101.     /*
  102.     MdxOpenLink(&LinkParams);
  103.     */
  104.  
  105.  
  106.     memset(&ProcessParams,0,sizeof(ProcessParams));
  107.     ProcessParams.ProcId                    =    CallId;
  108.     ProcessParams.InactivityTimer            =    6000;
  109.     ProcessParams.ConnectRetriesInterval    =    200;
  110.     MdxConnectProcess(&ProcessParams);
  111.     printf("(%ld) Calling %ld\n",MdxGetCurrTimerValue(),ProcessParams.ProcId);
  112.  
  113.     MdxSetApplTimer(ApplTimerDisplayTimer,1000,CallId,0,0,-1);
  114. }
  115.  
  116.  
  117. void    ApplSendMsgCompleted(
  118. TMdxEvent    *Event
  119. )
  120. {
  121.     TMdxSRMsgInfo        *MsgInfo;
  122.  
  123.     /*
  124.     "Event->Data"    holds the information abount the Message we sent.
  125.     */
  126.  
  127.     MsgInfo =    (TMdxSRMsgInfo    *)Event->Data;
  128.     switch(MsgInfo->Sent.MsgCode)
  129.     {
  130.         case    ApplGetTimeMsgCode    :
  131.         {
  132.             printf("(%ld) Time Sent - Error = %d\n",MdxGetCurrTimerValue(),Event->Error);
  133.         }
  134.         break;
  135.         default                     :    break;
  136.     }
  137. }
  138.  
  139.  
  140. void    ApplSendGetTimeReq(
  141. TMdxProcId    ProcId
  142. )
  143. {
  144.     if (    MdxSendData(ProcId,        /*    Target Process    */
  145.                     (UInt8Ptr)" ",        /*    Data            */
  146.                     1,                    /*    Data Size        */
  147.                     ApplGetTimeMsgCode,    /*    Msg Code        */
  148.                     0,                    /*    Priority        */
  149.                     MdxSendReliable,    /*    Send Attributes    */
  150.                                         /*    Success/Failure    */
  151.                                         /*    Report            */
  152.                     0,                    /*    No ReqSeq        */
  153.                     1000                    /*    3 Secs    Timeout    */
  154.                     )    !=    MdErrNoError    )
  155.     {
  156.         FatalErrorHandler("Mdx Send Error");
  157.     }
  158.     printf("(%ld) Sending Time Req To %ld\n",MdxGetCurrTimerValue(),ProcId);
  159. }
  160.  
  161. void    ApplTimerEvent(
  162. TMdxEvent    *Event
  163. )
  164. {
  165.     TMdxApplTimerInfo    TimerInfo;
  166.  
  167.     /*
  168.     "Event->Data"    holds the information abount the timer.
  169.     We use    "MdxGetApplTimerInfo()" to extract that info.
  170.     */
  171.  
  172.     MdxGetApplTimerInfo(Event->Data,&TimerInfo);
  173.  
  174.     switch(TimerInfo.Code)
  175.     {
  176.         case    ApplTimerDisplayTimer    :
  177.         {
  178.             ApplSendGetTimeReq(TimerInfo.Tag1);
  179.         }
  180.         break;
  181.         default :    break;
  182.     }
  183. }
  184.  
  185.  
  186. void    cdecl    ApplEventHandler(
  187. TMdxEvent    *Event
  188. )
  189. {
  190.     switch(Event->Code)
  191.     {
  192.         case    MdxTimerEvent                    :
  193.         {
  194.             ApplTimerEvent(Event);
  195.         }
  196.         break;
  197.         case    MdxEvSendMsgCompleted        :
  198.         {
  199.             ApplSendMsgCompleted(Event);
  200.         }
  201.         break;
  202.         case    MdxEventApplInit                :
  203.         {
  204.             ApplInitReceived();
  205.         }
  206.         break;
  207.         case    MdxEvCallCompleted            :
  208.         case    MdxEvCallRejected            :
  209.         {
  210.             ApplCallCompleted(Event);
  211.         }
  212.         break;
  213.         case    MdxEvDataReplyReceived        :
  214.         {
  215.             ApplDataReplyReceived(Event);
  216.         }
  217.         break;
  218.         case    MdxStdInAvailable                :
  219.         {
  220.             ApplShutdown    =    True;
  221.         }
  222.         break;
  223.         default                                 :    break;
  224.     }
  225. }
  226.  
  227.  
  228. Int cdecl    main(
  229. Int     Argc,
  230. Int8Ptr *Argv
  231. )
  232. {
  233.     if (    Argc    <    3    )
  234.     {
  235.         printf("Usage : client <MyId> <Node Id To Call>\n");
  236.         return(5);
  237.     }
  238.     MyId    =    atol(Argv[1]);
  239.     CallId    =    atol(Argv[2]);
  240.  
  241.     MultiXStart(MyId,"Client",0,ApplEventHandler);
  242.  
  243.     printf("Type any key to stop the program...\n");
  244.     while (    ApplShutdown    ==    False    )
  245.     {
  246.         MultiXWaitEvent();
  247.     }
  248.     return(0);
  249. }
  250.